package cn.lee.cplibrary.widget.edittext;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.Configuration;
import android.text.InputFilter;
import android.util.AttributeSet;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;

import cn.lee.cplibrary.init.CPInitializer;
import cn.lee.cplibrary.util.EditTextUtil;

/**
 * 只能输入2位小数的EdiText
 * Created by ChrisLee on 2021/7/17.
 */
public class PriceEditText extends ClearEditText {
    public PriceEditText(Context context) {
        super(context);
        init();
    }

    public PriceEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public PriceEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    //限制只能输入2位小数
    private void init() {
        CPInitializer.checkInitialization();
        setInputType(EditorInfo.TYPE_NUMBER_FLAG_DECIMAL);//小数数字
        InputFilter[] filtersPrice = {new DecimalInputFilter(2)};
        setFilters(filtersPrice);//2位
        setRawInputType(Configuration.KEYBOARD_QWERTY);//先调用数字键盘
        setSelection(getText().toString().length());//光标移动到最后一位
    }
}
